﻿using System.Diagnostics;
using System.Globalization;
using System.Linq;
using Orchard.Data;
using Orchard.Logging;
using Utils.WidgetInserter.Models;

namespace Utils.WidgetInserter.Services
{
    public class SettingsService : ISettingsService
    {
        private readonly IRepository<SettingsPartRecord> _repository;

        public ILogger Logger { get; set; }

        public SettingsService(IRepository<SettingsPartRecord> repository)
        {
            _repository = repository;
            Logger = NullLogger.Instance;
        }

        public SettingsPartRecord GetSettings()
        {
            //var stopwatch = new Stopwatch();
            //stopwatch.Start();  

            var result  = _repository.Table.FirstOrDefault();

            //stopwatch.Stop();
            
            //Logger.Debug("GetSettings: " + stopwatch.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture));
            //Logger.Error("GetSettings: " + stopwatch.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture));

            return result;
        }        
    }
}